package study.designpattern.flyweight;

public class MainFlyWeight {
    private static CoffeeFlavor[] flavors = new CoffeeFlavor[100];
    private static CoffeeOrderContext[] tables = new CoffeeOrderContext[100];
    private static CoffeeFlavorFactory cfFactory = new CoffeeFlavorFactory();
    private static int ordersMade = 0;
    public static void takeOrders(String flavor, int table){
        flavors[ordersMade] = cfFactory.getCoffeeFlavor(flavor);
        tables[ordersMade++] = new CoffeeOrderContext(table);
    }
    public static void main(String[] args) {
        takeOrders("Cappuccino", 2);
        takeOrders("Cappuccino", 2);
        takeOrders("Frappe", 1);
        takeOrders("Frappe", 1);
        takeOrders("Xpresso", 1);
        takeOrders("Frappe", 897);
        takeOrders("Cappuccino", 97);
        takeOrders("Cappuccino", 97);
        takeOrders("Frappe", 3);
        takeOrders("Xpresso", 3);
        takeOrders("Cappuccino", 3);
        takeOrders("Xpresso", 96);
        takeOrders("Frappe", 552);
        takeOrders("Cappuccino", 121);
        takeOrders("Xpresso", 121);
        
        for (int i = 0; i < ordersMade; ++i) {
            flavors[i].serveCoffee(tables[i]);
        }
        System.out.println(" ");
        System.out.println("total CoffeeFlavor objects made: " +  cfFactory.getTotalCoffeeFlavorsMade());
    }
}
